﻿//表单验证
$(function(){
	//var E=false,N=false,P=false,V=false;
	//当各项验证不能通过时，按钮点击无效
	$("#btnClientRegister").click(function(){
		/*if(E && N && P && V){
			return false;
		}else{
			return true;
		}*/
		var E=false,N=false,P=false,V=false;
		var email = $("#txtEmail").val();
		var name = $("#txtNickName").val();
		var pwd = $("#txtPassword").val();
		var code = $("#txtVerifyCode").val();
		if(email == "" || name == "" || pwd == "" || code == ""){
			return false;
		}else{
			return true;
		}
		
	});
	
	//email地址
	var e_color = $("#email\\.info").css("color");
	$("#txtEmail").blur(function(){
		E = false;
		var val = $(this).val();
		var info = $("#email\\.info");
		info.html("");
		info.css("color",e_color);
		if(val == ""){
			info.text("Email不能为空");
		}else if(!val.match(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/)){
			info.text("Email格式不正确");
		}else{
			info.html("<img src='./img/11.png'/>恭喜，该Email可用").css('color','green');
			E = true;
		}
	});
	
//ID
$("#txtNickName").blur(function(){
	N = false;
	var val= $(this).val();
	var info = $("#name\\.info");
	info.html("");
	if(val == ""){
		info.text("ID不能为空");
	}else if(!val.match(/^[0-9]{1,11}$/)){
		info.text("ID格式不正确");
	}else{
		N = true;
		info.html("<img src='./img/11.png'/>");
	}
});

//手机号
$("#txtPassword").blur(function(){
	p = false;
	var val = $(this).val();
	var info = $("#password\\.info");
	info.html("");
	if(val == ""){
		info.text("手机号不能为空");
	}else if(!val.match(/^[0-9]{7,13}$/)){
		info.text("手机号格式不正确");
	}else{
		p = true;
		info.html("<img src='./img/11.png'/>");
	}
});

//验证码
$("#txtVerifyCode").blur(function(){
	V = false;
	var val = $(this).val();
	var info = $("#number\\.info");
	info.html("");
	if(val == ""){
		info.text("验证码不能为空");
	}else{
		$.post("validateCheckCode.do",
				{'checkCode':val},
				function(data){
					if(data.flag){
						info.html("<img src='./img/11.png'/>");
						V = true;
					}else{
						info.text("验证码错误");
					}
				},
				'json'
		);
	}
});

});

//刷新验证码
$(function(){
	$("#checkCode").click(function(){
		$("#imgVcode").attr("src","checkCode.action?dt="+new Date().getTime());
	});
});